//package com.dlc.shop.jky.platform.controller;
//
//import cn.hutool.http.HttpRequest;
//import cn.hutool.http.HttpResponse;
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONObject;
//import io.swagger.v3.oas.annotations.Operation;
//import jakarta.servlet.http.HttpServletRequest;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.io.BufferedReader;
//import java.io.IOException;
//import java.security.NoSuchAlgorithmException;
//import java.text.ParseException;
//import java.util.Date;
//
//@Slf4j
//@RestController
//@RequestMapping("/dukpay")
//public class russiaController {
////支付订单
//    public static void main(String[] args) throws NoSuchAlgorithmException {
//       // String url = "https://pre-payment.dukpay.com/public/merchant";
//        String url = "https://pre-payment.dukpay.com/public/merchant";
//        // secretId
//        String secretId = "e1qkxzae1b99cmkz9bcn5pj3id608qjg";
//        // secretKey
//        String secretKey = "f61bat053mr30lk3m0vxfo38maboeghq";
//        // 接口编码
//        String apiCode = "orderCreateV2";
//        // 请求标识
//        String requestKey = "dlchome@mail.ru";
//        // orderNo
//        String orderNo = "1";
//        // 请求体信息，！！！注意：签名使用的请求体请与实际发送的请求体一致！！！
//
//
//        orderCreateV2DukPay pay =new orderCreateV2DukPay();
//        pay.setBusinessNo("1");
//        pay.setRequestTime(new Date().getTime());
//        pay.setCountry("RUS");
//        pay.setPaymentMethod("BANK_CARD");
//        pay.setCurrency("RUB");
//        pay.setCallbackUrl("http://ccy9wv.natappfree.cc/dukpay/paymentOrderCallback");
//       // pay.setRedirectUrl("https://dlchm.cn/platform/home");
//        pay.setOrderAmount(0.01);
//        orderCreateV2DukPay.orderCreateV2Properties orderCreateV2Properties = new orderCreateV2DukPay.orderCreateV2Properties();
//        orderCreateV2Properties.setClientIp("169.254.185.250");
//
//        String requestBody = JSON.toJSONString(pay);
//        // 最终待签名字符串 ${secretId}${secretKey}${requestKey}${api}${requestBody}
//        String strToSign = secretId + secretKey + requestKey + apiCode + requestBody;
//        System.out.println("strToSign:[" + strToSign + "]");
//        // 签名结果
//        String result = Sign.md5(strToSign);
//        // 构建POST请求
//        HttpRequest request = HttpRequest.post(url)
//                .header("Content-Type", "application/json")
//                .header("Authorization","SecretId=e1qkxzae1b99cmkz9bcn5pj3id608qjg,Signature="+result)// 设置请求头
//                .header("X-DUKPAY-API","orderCreateV2")
//                .header("X-DUKPAY-REQ-KEY","dlchome@mail.ru")
//                .body(JSON.toJSONString(pay)); // 设置请求体，这里是一个JSON字符串
//
//        // 发送请求，并接收响应
//        HttpResponse response = request.execute();
//
//        // 打印响应的内容
//        log.info(request.getUrl() + ";返回结果为：------------》"+response.body());
//    }
//    //退款订单
////    public static void main(String[] args) throws NoSuchAlgorithmException {
////        String url = "https://pre-payment.dukpay.com/public/merchant";
////        // secretId
////        String secretId = "e1qkxzae1b99cmkz9bcn5pj3id608qjg";
////        // secretKey
////        String secretKey = "f61bat053mr30lk3m0vxfo38maboeghq";
////        // 接口编码
////        String apiCode = "refund";
////        // 请求标识
////        String requestKey = "dlchome@mail.ru";
////        // orderNo
////        String orderNo = "1";
////        // 请求体信息，！！！注意：签名使用的请求体请与实际发送的请求体一致！！！
////
////
////        refundDukPay pay =new refundDukPay();
////        pay.setBusinessNo("1");
////        pay.setAmount(0.01);
////        pay.setReason("不想要了");
////        pay.setSourceOrderNo("P1805862339908624384");
////        pay.setCallbackUrl("http://ccy9wv.natappfree.cc/dukpay/refundOrderCallback");
////        String requestBody = JSON.toJSONString(pay);
////        // 最终待签名字符串 ${secretId}${secretKey}${requestKey}${api}${requestBody}
////        String strToSign = secretId + secretKey + requestKey + apiCode + requestBody;
////        System.out.println("strToSign:[" + strToSign + "]");
////        // 签名结果
////        String result = Sign.md5(strToSign);
////        // 构建POST请求
////        HttpRequest request = HttpRequest.post(url)
////                .header("Content-Type", "application/json")
////                .header("Authorization","SecretId=e1qkxzae1b99cmkz9bcn5pj3id608qjg,Signature="+result)// 设置请求头
////                .header("X-DUKPAY-API","refund")
////                .header("X-DUKPAY-REQ-KEY","dlchome@mail.ru")
////                .body(JSON.toJSONString(pay)); // 设置请求体，这里是一个JSON字符串
////
////        // 发送请求，并接收响应
////        HttpResponse response = request.execute();
////
////        // 打印响应的内容
////        log.info(request.getUrl() + ";返回结果为：------------》"+response.body());
////    }
//
//
//    @PostMapping("/paymentOrderCallback")
//    @Operation(summary = "dukpay收款订单回调")
//    public String paymentOrderCallback(HttpServletRequest request) throws ParseException, IOException {
//// X-DUKPAY-REQ-KEY         string   true   请求标识
////    X-DUKPAY-API            string   true   固定值:dukpay-callback
////    X-DUKPAY-RESP-SIGN            string   true   签名，请校验签名， 防止被篡改。签名逻辑与商户请求dukpay的签名逻辑一致
////    callback-type           string  true  payment_order收款订单，payout_order代付订单，refund_order退款订单，subscription_order订阅订单，withhold_order代扣订单
//        String key = request.getHeader("X-DUKPAY-REQ-KEY");
//        String api = request.getHeader("X-DUKPAY-API");
//        String sign = request.getHeader("X-DUKPAY-RESP-SIGN");
//        String type = request.getHeader("callback-type");
//
//        if (type.equals("payment_order")){
//           // request.getParameter("boby");
//            StringBuilder requestBody = new StringBuilder();
//            BufferedReader reader = request.getReader();
//            String line;
//            while ((line = reader.readLine()) != null) {
//                requestBody.append(line);
//            }
//            // 解析JSON数据
//            DukpayCallback json = JSONObject.parseObject(requestBody.toString(), DukpayCallback.class);
//            System.out.println(
//                   "支付成功回调：" +json
//            );
//           // {"refNo":"P1805855035565957120","finishTime":1719384514200,"serviceFeeDetails":[{"amount":0.00,"currency":"RUB","feeType":"service_fee"}],"orderNo":"P1805855035565957120","reconciliationDate":"2024-06-26","totalServiceFee":0.00,"businessNo":"2222222222222224444","orderAmount":0.01,"createTime":1719384366000,"paymentMethod":"BANK_CARD","currency":"RUB","channelAttrs":{},"status":"success"}
//        }
//        return "{code: 0}";
//
//    }
//
//
//    @PostMapping("/refundOrderCallback")
//    @Operation(summary = "dukpay退款订单回调")
//    public String refundOrderCallback(HttpServletRequest request) throws ParseException, IOException {
//// X-DUKPAY-REQ-KEY         string   true   请求标识
////    X-DUKPAY-API            string   true   固定值:dukpay-callback
////    X-DUKPAY-RESP-SIGN            string   true   签名，请校验签名， 防止被篡改。签名逻辑与商户请求dukpay的签名逻辑一致
////    callback-type           string  true  payment_order收款订单，payout_order代付订单，refund_order退款订单，
////    subscription_order订阅订单，withhold_order代扣订单
//        String key = request.getHeader("X-DUKPAY-REQ-KEY");
//        String api = request.getHeader("X-DUKPAY-API");
//        String sign = request.getHeader("X-DUKPAY-RESP-SIGN");
//        String type = request.getHeader("callback-type");
//
//        if (type.equals("refund_order")){
//            // request.getParameter("boby");
//            StringBuilder requestBody = new StringBuilder();
//            BufferedReader reader = request.getReader();
//            String line;
//            while ((line = reader.readLine()) != null) {
//                requestBody.append(line);
//            }
//            // 解析JSON数据
//            redundCallback json = JSONObject.parseObject(requestBody.toString(), redundCallback.class);
//            if(json.getStatus().equals("success")){
//                System.out.println("退款回调成功");
//            }
//            if (json.getStatus().equals("failed")){
//                System.out.println("退款回调 失败");
//            }
//            System.out.println(
//                    "支付成功回调：" +json
//            );
//            // {"refNo":"P1805855035565957120","finishTime":1719384514200,"serviceFeeDetails":[{"amount":0.00,"currency":"RUB","feeType":"service_fee"}],"orderNo":"P1805855035565957120","reconciliationDate":"2024-06-26","totalServiceFee":0.00,"businessNo":"2222222222222224444","orderAmount":0.01,"createTime":1719384366000,"paymentMethod":"BANK_CARD","currency":"RUB","channelAttrs":{},"status":"success"}
//        }
//        return "{code: 0}";
//    }
//   }
